package com.egg.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.egg.dao.BaseDao;
import com.egg.service.UserService;
/**
 * @项目名称：egg   
 * @类名称：UserServiceImpl   
 * @类描述：用户管理实现   
 * @创建人：wangchenyang
 * @创建时间：2012-8-31 上午10:49:03   
 * @修改人：
 * @修改时间：   
 * @修改备注：   
 * @version
 */
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	BaseDao baseDao;
	@Override
	public List<Map<String, Object>> getAllUser(Object...obj) {
		StringBuffer sb=new StringBuffer();
		sb.append("SELECT EU.ID,"); 
		sb.append("   EU.USER_ACCOUNT,");  
		sb.append("   EU.USER_NAME,");  
		sb.append("   CASE");  
		sb.append("     WHEN EU.USER_SEX = 1 THEN");  
		sb.append("      '男'");  
		sb.append("     WHEN EU.USER_SEX = 0 THEN");  
		sb.append("      '女'");  
		sb.append("   END AS USER_SEX,");  
		sb.append("   CASE");  
		sb.append("     WHEN EU.USER_STATUS = 1 THEN");  
		sb.append("      '已激活'");  
		sb.append("     WHEN EU.USER_STATUS = 0 THEN");  
		sb.append("      '未激活'");  
		sb.append("   END AS USER_STATUS,");  
		sb.append("   EU.USER_PHONE");  
		sb.append("  FROM EGG_USER EU ");  
		sb.append(" WHERE EU.DEPT_ID=? AND EU.ID!=?");
		return baseDao.queryForList(sb.toString(),obj);
	}
	/**
	 * 添加用户
	 * @param obj
	 * @see com.egg.service.UserService#addUser(java.lang.Object[])
	 */
	@Override
	public void addUser(Object... obj) {
		String sql="INSERT INTO EGG_USER(ID,USER_ACCOUNT,USER_NAME,USER_PASSWORD,USER_SEX,USER_TYPE,DEPT_ID,USER_PHONE,CREATE_TIME) VALUES(SEQ_EGG_USER.NEXTVAL,?,?,?,?,?,?,?,?)";
		baseDao.update(sql, obj);
	}
	/**
	 * 更新用户 
	 * @param obj
	 * @see com.egg.service.UserService#updateUser(java.lang.Object[])
	 */
	@Override
	public void updateUser(Object... obj) {
		String sql="UPDATE EGG_USER SET USER_ACCOUNT=?,USER_NAME=?,USER_PASSWORD=?,USER_SEX=?,USER_TYPE=?,DEPT_ID=?,USER_PHONE=? WHERE ID=?";
		baseDao.update(sql, obj);
	}
	/**
	 * 删除用户
	 * @param obj
	 * @see com.egg.service.UserService#deleteUser(java.lang.Object[])
	 */
	@Override
	public void deleteUser(Object... obj) {
		String sql="DELETE FROM EGG_USER WHERE ID=?";
		baseDao.update(sql, obj);
	}
	@Override
	public List<Map<String, Object>> getOneUser(Object...obj) {
		String sql="SELECT * FROM EGG_USER WHERE ID=?";
		return baseDao.queryForList(sql, obj);
	}
	@Override
	public List<Map<String, Object>> getAllSystemManager(Object... obj) {
		StringBuffer sb=new StringBuffer();
		sb.append("SELECT EU.ID,"); 
		sb.append("   EU.USER_ACCOUNT,");  
		sb.append("   EU.USER_NAME,");  
		sb.append("   CASE");  
		sb.append("     WHEN EU.USER_SEX = 1 THEN");  
		sb.append("      '男'");  
		sb.append("     WHEN EU.USER_SEX = 0 THEN");  
		sb.append("      '女'");  
		sb.append("   END AS USER_SEX,");  
		sb.append("   CASE");  
		sb.append("     WHEN EU.USER_STATUS = 1 THEN");  
		sb.append("      '已激活'");  
		sb.append("     WHEN EU.USER_STATUS = 0 THEN");  
		sb.append("      '未激活'");  
		sb.append("   END AS USER_STATUS,");  
		sb.append("   EU.USER_PHONE");  
		sb.append("  FROM EGG_USER EU ");  
		sb.append(" WHERE EU.USER_TYPE=?");
		return baseDao.queryForList(sb.toString(), obj);
	}


}
